home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-03-08 | 12.3 KB | 331 lines | [TEXT/EMAC] |
- ;;;
- ;;; Apple event support for the Think Project Manager
- ;;;
-
- (defun tc:send-parameterless (eventType description)
- (let* (event
- (reply (make-string sizeof-AppleEvent 0))
- transactionID
- (result
- (catch 'panic
- (throw-err (create-think-c-apple-event "KAHL" eventType
- event transactionID))
- (throw-err (AESend event reply (+ kAEQueueReply kAENeverInteract)
- kAENormalPriority 0 0 0))
- (setq ae-history (cons (cons transactionID
- (list (cons 'description description)
- (cons 'handler 'do-simple-reply)))
- ae-history))
- noErr)))
- (if event (AEDisposeDesc event))
- result))
- ;
- ; -----------------------------------------------------------------------
- ; -----------------------------------------------------------------------
- ;
- ; Modified --- the editor sends this event to notify THINK that a file has been modified
- ; at the specified time. The editor should send this event when saving a
- ; file and when closing a file.
- ;
- ; Event Class: 'KAHL'
- ; Event ID: 'MOD '
- ; Parameters:
- ;
- ; keyDirectObject (AEDescList of the following structs (typeChar), one for each file)
- ; struct {
- ; FSSpec fss; // the file spec
- ; long when; // the modified time
- ; short saved; // is the file being saved? 0 == no.
- ; };
-
- ; -----------------------------------------------------------------------
- ; -----------------------------------------------------------------------
- ;
- ; Find In Next File --- the editor sends this event to prompt THINK to execute its
- ; Find In Next File command. This provides better THINK/Editor
- ; integration during multi-file searches.
- ;
- ; Event Class: 'KAHL'
- ; Event ID: 'FINF'
- ; Parameters: none
-
- (defun tc:send-finf ()
- (tc:send-parameterless "FINF" "find-in-next-file"))
-
- ; -----------------------------------------------------------------------
- ; -----------------------------------------------------------------------
- ;
- ; Goto Next Match --- the editor sends this event to prompt THINK to execute its
- ; Go To Next Match/Error command. This provides better THINK/Editor
- ; integration during batch compiles and batch searches.
- ;
- ; Event Class: 'KAHL'
- ; Event ID: 'NMAT'
- ; Parameters: none
-
- (defun tc:send-nmat ()
- (tc:send-parameterless "NMAT" "goto-next-match"))
-
- ; -----------------------------------------------------------------------
- ; -----------------------------------------------------------------------
- ;
- ; Goto Previous Match --- the editor sends this event to prompt THINK to execute its
- ; Go To Previous Match/Error command. This provides better
- ; THINK/Editor integration during batch compiles and batch
- ; searches.
- ;
- ; Event Class: 'KAHL'
- ; Event ID: 'PMAT'
- ; Parameters: none
-
- (defun tc:send-pmat ()
- (tc:send-parameterless "PMAT" "goto-previous-match"))
-
- ; -----------------------------------------------------------------------
- ; -----------------------------------------------------------------------
- ;
- ; Get Markers --- the editor sends this event to ask THINK for a file's marker and
- ; Debugger state data. The editor should send this event whenever
- ; it opens a file.
- ;
- ; Event Class: 'KAHL'
- ; Event ID: 'GTMK'
- ; Parameters:
- ;
- ; keyDirectObject (AEDescList of FSSpecs (typeFSS), one for each file)
- ; Indicates the file(s) just opened.
- ;
- ; 'CLBK' (typeChar, required)
- ; Specifies callback functions to be used by THINK in getting the marker data.
- ;
- ; struct {
- ; long GetNumLines; // Pointer to a function that returns the number of
- ; // lines in a file.
- ; long GetCharPos; // Pointer to a function that returns the character
- ; // position for the first character in a given line
- ; // of a file.
- ; long refcon; // A 32-bit data element that THINK will pass back as
- ; // the first parameter of the GetNumLines and GetCharPos
- ; // functions.
- ; };
- ;
- ; Reply Parameters:
- ;
- ; keyDirectObject (AEDescList of the following structs (typeChar), one for each file)
- ;
- ; struct {
- ; Handle markers, breakpoints, dataviews, lineOffsets;
- ; long **bkptIDs, **dtvuIDs, **bkptSizes, **dtvuSizes;
- ; };
-
- (defun tc:send-gtmk ()
- (let* (event
- (reply (make-string sizeof-AppleEvent 0))
- transactionID
- spec
- (clbk-data (make-string 12 0))
- (file-name (buffer-file-name))
- (result
- (catch 'panic
- (throw-err (create-think-c-apple-event "KAHL" "GTMK"
- event transactionID))
- (if (null file-name) (throw-err errAEEventNotHandled))
- (throw-err (unix-filename-to-FSSpec file-name spec))
- (throw-err (AEPutParamPtr event keyDirectObject typeFSS
- spec (length spec)))
- (encode-internal clbk-data 0 'unsigned-long tc:GetNumLines)
- (encode-internal clbk-data 4 'unsigned-long tc:GetCharPos)
- (encode-internal clbk-data 8 'verbatim-long (current-buffer))
- (throw-err (AEPutParamPtr event "CLBK" typeChar
- clbk-data (length clbk-data)))
- (throw-err (AESend event reply (+ kAEQueueReply kAENeverInteract)
- kAENormalPriority 0 0 0))
- (setq ae-history (cons (cons transactionID
- (list (cons 'description "get-markers")
- (cons 'handler 'tc:do-gtmk-reply)
- (cons 'buffer (current-buffer))))
- ae-history))
- noErr)))
- (if event (AEDisposeDesc event))
- result))
-
- (defun tc:try-sending-gtmk ()
- ;;; This will avoid settting tc:have-TPM-data if there is none at all to be had.
- ; (if (tc:file-in-project-p (file-name-nondirectory
- ; (buffer-file-name (current-buffer)))))
- (tc:send-gtmk))
-
- ;;; "Whenever we open a file..."
- (if (not (memq (function tc:send-gtmk) find-file-hooks))
- (setq find-file-hooks (cons (function tc:try-sending-gtmk) find-file-hooks)))
-
- (defun tc:do-gtmk-reply (event history)
- (let* ((theList (make-string sizeof-AEDesc 0))
- (theCount-string (make-string sizeof-long 0))
- theCount-integer
- (theAEKeyword (make-string sizeof-long 0))
- (typeCode (make-string sizeof-long 0))
- (dataPtr (make-string (* 8 sizeof-long) 0))
- (actualSize (make-string sizeof-long 0))
- (result
- (catch 'panic
- (throw-err (AEGetParamDesc event keyDirectObject typeAEList theList))
- (throw-err (AECountItems theList theCount-string))
- (setq theCount-integer (extract-internal theCount-string 0 'long))
- (if (not (= theCount-integer 1))
- errAEEventNotHandled
- (throw-err (AEGetNthPtr theList 1 typeChar theAEKeyword
- typeCode dataPtr (* 8 sizeof-int) actualSize))
- (let ((buffer (cdr (assoc 'buffer history))))
- (set-buffer buffer)
- (setf-tc:markers (extract-internal dataPtr 0 'unsigned-long))
- (setf-tc:breakpoints (extract-internal dataPtr 4 'unsigned-long))
- (setf-tc:dataviews (extract-internal dataPtr 8 'unsigned-long))
- (setf-tc:lineOffsets (extract-internal dataPtr 12 'unsigned-long))
- (setf-tc:bkptIDs (extract-internal dataPtr 16 'unsigned-long))
- (setf-tc:dtvuIDs (extract-internal dataPtr 20 'unsigned-long))
- (setf-tc:bkptSizes (extract-internal dataPtr 24 'unsigned-long))
- (setf-tc:dtvuSizes (extract-internal dataPtr 28 'unsigned-long))
- (setq tc:oldSelStart (tc:selStart))
- (setq tc:oldSelEnd (tc:selEnd))
- (setq tc:oldTextLength (tc:textLen))
- (setq tc:oldNumLines (tc:numLines))
- (setq tc:oldLineStart (tc:lineStart))
- (setq tc:oldLineEnd (tc:lineEnd))
- (setq tc:have-TPM-data t))))
- noErr))
- (if theList (AEDisposeDesc theList))
- result))
-
- ; -----------------------------------------------------------------------
- ; -----------------------------------------------------------------------
- ;
- ; Put Markers --- the editor sends this event when it wants THINK to store marker and
- ; Debugger state data into a disk file. The editor should send this
- ; event whenever it saves a file.
- ;
- ; Event Class: 'KAHL'
- ; Event ID: 'PTMK'
- ; Parameters:
- ;
- ; keyDirectObject (AEDescList of the following structs (typeChar), one for each file)
- ;
- ; struct {
- ; short copyfile, // Are we making a copy of the file to a disk file of
- ; // a different name (like THINK's "Save A Copy As…")?
- ; newfile; // Are we creating a new disk file (vs. saving to an
- ; // old one?)
- ; FSSpec fss; // The file spec.
- ; Handle markers, breakpoints, dataviews, lineOffsets; // The marker and
- ; long **bkptIDs, **dtvuIDs, **bkptSizes, **dtvuSizes; // Debugger data.
- ; };
-
- (c:defstruct tc:struct-ptmk ((short copyfile)
- (short newfile)
- (FSSpec fss)
- (long markers)
- (long breakpoints)
- (long dataviews)
- (long lineOffsets)
- (long bkptIDs)
- (long dtvuIDs)
- (long bkptSizes)
- (long dtvuSizes)))
-
- (defun tc:send-ptmk (copyfile newfile spec)
- (let ((obj (make-string (c:sizeof 'tc:struct-ptmk) 0)))
- (c:slotset 'tc:struct-ptmk obj 'copyfile copyfile)
- (c:slotset 'tc:struct-ptmk obj 'newfile newfile)
- (c:slotset 'tc:struct-ptmk obj 'fss spec)
- (c:slotset 'tc:struct-ptmk obj 'markers (tc:markers))
- (c:slotset 'tc:struct-ptmk obj 'breakpoints (tc:breakpoints))
- (c:slotset 'tc:struct-ptmk obj 'dataviews (tc:dataviews))
- (c:slotset 'tc:struct-ptmk obj 'lineOffsets (tc:lineOffsets))
- (c:slotset 'tc:struct-ptmk obj 'bkptIDs (tc:bkptIDs))
- (c:slotset 'tc:struct-ptmk obj 'dtvuIDs (tc:dtvuIDs))
- (c:slotset 'tc:struct-ptmk obj 'bkptSizes (tc:bkptSizes))
- (c:slotset 'tc:struct-ptmk obj 'dtvuSizes (tc:dtvuSizes))
- (let (event
- (reply (make-string sizeof-AppleEvent 0))
- transactionID
- (result
- (catch 'panic
- (throw-err (create-think-c-apple-event "KAHL" "PTMK"
- event transactionID))
- (throw-err (AEPutParamPtr event keyDirectObject typeChar
- obj (length obj)))
- (throw-err (AESend event reply (+ kAEQueueReply kAENeverInteract)
- kAENormalPriority 0 0 0))
- (setq ae-history (cons (cons transactionID
- (list (cons 'description "put-markers")
- (cons 'handler 'do-simple-reply)))
- ae-history))
- noErr)))
- (if event (AEDisposeDesc event))
- result)))
-
- ; -----------------------------------------------------------------------
- ; -----------------------------------------------------------------------
- ;
- ; Update Markers --- the editor sends this event when it needs THINK to update a file's
- ; marker and Debugger state information (this involves changing the
- ; marker locations to reflect the addition or deletion of characters
- ; at a given location in the file). For some guidelines on when to
- ; send this event, refer to the MiniEdit source code.
- ;
- ; Event Class: 'KAHL'
- ; Event ID: 'MKUP'
- ; Parameters:
- ;
- ; keyDirectObject (AEDescList of the following structs (typeChar), one for each file)
- ;
- ; struct {
- ; Handle markers, breakpoints, dataviews, lineOffsets, dtvuIDs;
- ; long oldSelStart, oldSelEnd, oldTextLength,
- ; oldLineStart, oldLineEnd, oldNumLines,
- ; newTextLength, newNumLines, newSelEnd;
- ; long refcon; // A 32-bit data element that THINK will pass back as
- ; // the first parameter of the GetLineNum function.
- ; };
- ;
- ; 'CLBK' (typeChar, required)
- ; Pointer to a callback function to be used by THINK in getting the marker data.
- ; The function, GetLineNum, returns the line which contains a given
- ; character position.
-
- (defun tc:send-mkup (buffer)
- (let ((mkup (make-mkup buffer)))
- (if mkup
- (let* (event
- transactionID
- (reply (make-string sizeof-AppleEvent 0))
- (callback-data (encode-long-integer tc:GetLineNum))
- (result
- (catch 'panic
- (throw-err (create-think-c-apple-event "KAHL" "MKUP" event transactionID))
- (throw-err (AEPutParamPtr event keyDirectObject typeChar mkup (length mkup)))
- (throw-err (AEPutParamPtr event "CLBK" typeChar callback-data sizeof-long))
- (throw-err (AESend event reply (+ kAEQueueReply kAENeverInteract)
- kAENormalPriority 0 0 0))
- (setq ae-history (cons (cons transactionID
- (list (cons 'description "marker-update")
- (cons 'handler 'do-simple-reply)))
- ae-history))
- noErr)))
- (if event (AEDisposeDesc event))
- result))))
-
- ; -----------------------------------------------------------------------
- ; -----------------------------------------------------------------------
- ;
- ; CloseProject --- the editor can send this event in response to a CloseProject event
- ; from THINK. Sending this event tells THINK to complete its pending
- ; Close Project command.
- ;
- ; Event Class: 'KAHL'
- ; Event ID: 'CPRJ'
- ; Parameters: none
-
- (defun tc:send-cprj ()
- (tc:send-parameterless "CPRJ" "close-project"))
-